pub mod lmqtt;


use std::fmt::format;
use crate::lmqtt::ltopic;
use lmqtt::ldata::LMessage;

use lipo_base::ltools::lrand;
use crate::lmqtt::ldata::MessageType;

pub(crate) const  RAND_UUID_LEN:u8 = 16;

pub fn send_text(send_id:String, recv_id: &String, content:String){
    let topic = format!("{}/{}",ltopic::MQTT_TOPIC_HEAD_MSG, recv_id);
    tokio::spawn(async move {
        let msg_id = lrand::generate_random_string(RAND_UUID_LEN);
        
        let message_data = LMessage::new_s(
            msg_id.clone(),
            send_id,
            MessageType::Text,
            content
        );
        
        lmqtt::publish
            (topic, msg_id, message_data.to_vec(), 1).await
    });
}
